//
//  LLT_VideoTableViewCell_LXH.m
//  CoderLLT
//
//  Created by lanou3g on 15/12/15.
//  Copyright © 2015年 刘晓萌. All rights reserved.
//

#import "LLT_VideoTableViewCell_LXH.h"
#import "LLT_PersonModel.h"
#import "UIImageView+WebCache.h"

@interface LLT_VideoTableViewCell_LXH()

@property (weak, nonatomic) IBOutlet UIImageView *personImageView;

@property (weak, nonatomic) IBOutlet UILabel *personNameLabel;

@property (weak, nonatomic) IBOutlet UILabel *personCountLabel;
@property (weak, nonatomic) IBOutlet UILabel *recentTimeLabel;

@end

@implementation LLT_VideoTableViewCell_LXH

/**
 * dealloc
 */
-(void)dealloc{
    
    self.personModel = nil;
    self.personImageView = nil;
    self.personCountLabel = nil;
    self.personNameLabel = nil;
    self.recentTimeLabel = nil;
    
}

-(void)setPersonModel:(LLT_PersonModel *)personModel{
    if (_personModel != personModel) {
        _personModel = nil;
        _personModel = personModel;
    }
    [self setupView];

}

-(void)setupView{
    
    self.personImageView.layer.masksToBounds = YES;
    self.personImageView.layer.cornerRadius = CGRectGetWidth(self.personImageView.frame)/2;
    
    if ([self.personModel.username isEqualToString:@"最新视频"]) {
        self.personImageView.image = [UIImage imageNamed:@"newVideo"];
    }else{
        [self.personImageView sd_setImageWithURL:[NSURL URLWithString:self.personModel.avatar]placeholderImage:[UIImage imageNamed:@"mhead"]];
    }
    

    
    self.personNameLabel.text = [NSString stringWithFormat:@"%@",self.personModel.username];
    
    if (self.personModel.count == nil) {
        
        self.personCountLabel.text = @"";
        
        self.recentTimeLabel.text = @"";
        
    }else{

        self.personCountLabel.text = [NSString stringWithFormat:@"%@个视频",self.personModel.count];
        
        self.recentTimeLabel.text = [self getNewsDateLabelTextByString:self.personModel.recent_time];
        
    }

    
    
    
}


/**
 * 计算时间的方法
 */
-(NSString *)getNewsDateLabelTextByString:(NSString *)string{
    
    long long int date1 = (long long int) [string intValue];
    NSDate *currentDate = [NSDate date];
    NSTimeInterval currentInterval = [currentDate timeIntervalSince1970];
    NSMutableString *s = [NSMutableString string];
    
    NSTimeInterval interval = date1 - currentInterval;
    
    if (interval > -1 * 60 *60) {
        NSInteger count = interval / 60;
        s = [NSMutableString stringWithFormat:@"🕘 %ld分钟前",-count];
    }else if(interval > - 24 * 60 * 60) {
        NSInteger count = interval / (60 * 60);
        s = [NSMutableString stringWithFormat:@"🕘 %ld小时前",-count];
    }else if (interval > - 30 * 24 * 60 * 60){
        NSInteger count = interval / (24 * 60 * 60);
        s = [NSMutableString stringWithFormat:@"🕘 %ld天前",-count];
    }else{
        NSInteger count = interval / (24 * 60 * 60);
        s = [NSMutableString stringWithFormat:@"🕘 %ld天前",-count];
    }
    return s;
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
